package auctionatr

import grails.test.*

class AuctionTests extends GrailsUnitTestCase {
    def testauction
    protected void setUp() {
        super.setUp()
		
		mockForConstraintsTests(Auction)
		 testauction = new Auction(
			name:"iPhone 4",
			description:"Ich verkaufe ein nagelneues iPhone 4!",
			startPrice:1.0,
			dateCreated:new Date(),
			
			deliveryCosts: 0,
			
			finishDate:(new Date()+1),
			
			
			shipment:"UPS",
			state:"neu",
			picture:null,
			pictureType:null,
			users: new User(),
			categories:new Category()
			)
	}	

    protected void tearDown() {
        super.tearDown()
    }

    void testName() {
		testauction.name='1234567890101112141516171819202122232425262728293031323334353637383940'
		assertFalse "Validation should not succeed",
			testauction.validate()
			
		assertTrue "There should be errors",
			testauction.hasErrors()
			println "\nErrors:"
			println testauction.errors ?: "no errors found"
			
		testauction.name='iPhone 4S'
		
		assertTrue "Validation should succeed",
			testauction.validate()

    }
	
	void testFinishDate(){
		testauction.finishDate=testauction.dateCreated - 1
		assertFalse "Validation should not succeed",
			testauction.validate()
		
		testauction.finishDate=new Date()+14
	
		assertTrue "Validation should succeed",
			testauction.validate()
	}

	void testStartPrice(){
		testauction.startPrice= -1
		assertFalse "Validation should not succeed",
			testauction.validate()
						
		testauction.startPrice = 14
	
		assertTrue "Validation should succeed",
			testauction.validate()
	}
	
	void testState(){
		testauction.state="alt"
		assertFalse "Validation should not succeed",
			testauction.validate()
			
		assertTrue "There should be errors",
			testauction.hasErrors()
			println "\nErrors:"
			println testauction.errors ?: "no errors found"
						
		testauction.state = "neu"
	
		assertTrue "Validation should succeed",
			testauction.validate()
	}
	
	void testShipment(){
		testauction.shipment="niemand"
		assertFalse "Validation should not succeed",
			testauction.validate()
			
		assertTrue "There should be errors",
			testauction.hasErrors()
			println "\nErrors:"
			println testauction.errors ?: "no errors found"
						
		testauction.shipment = "Hermes"
		assertTrue "Validation should succeed",
			testauction.validate()
	}
	
	void testDeliveryCosts(){
		testauction.deliveryCosts= -1
		assertFalse "Validation should not succeed",
			testauction.validate()
						
		testauction.deliveryCosts = 14
	
		assertTrue "Validation should succeed",
			testauction.validate()
	}
	
}
